<?php
/**
*
* 程序模块文件
*
* @package  ShopEx网上商店系统
* @version  4.6
* @author   ShopEx.cn <develop@shopex.cn>
* @url		http://www.shopex.cn/
* @since    PHP 4.3
* @copyright ShopEx.cn
*
**/
if (!defined("ISSHOP"))
{
	Header("Location:../index.php");
	exit;
}
$shopinfo = newclass("indexShop");
$shopinfo->getbyId($INC_SHOPID);
$newsignstr = md5($_GET["orderid"].$shopinfo->userName.$shopinfo->password);

//if ($_GET["signstr"] != $newsignstr)
//{
//	echo "check valid fail";
//	exit;
//}
//else
//{
	switch ($_GET["state"])
	{
		//验证失败
		case "0":
			if(!empty($_GET["strinfo"]))
				$reply_title = $_GET["strinfo"];
			else
				$reply_title = $PROG_TAGS["ptag_1282"];
			break;
		//支付失败
		case "1":
			if(!empty($_GET["strinfo"]))
				$reply_title = $_GET["strinfo"];
			else
				$reply_title = $PROG_TAGS["ptag_1285"];
			break;
		//成功支付
		case "2":
			if(!empty($_GET["strinfo"]))
				$reply_title = $_GET["strinfo"];
			else
				$reply_title = $PROG_TAGS["ptag_1281"];

			$Order = newclass("Order");
			error_log(print_r($_GET,true),3,__FILE__.'._GET.log');	//alone
			if($Order->getOrderBySign($_GET['signstr'])){
				error_log(print_r($Order,true),3,__FILE__.'.Order.log');	//alone
				if($_GET["orderid"] != $Order->orderId){
					echo 'Invalid signature';
					exit;
				}
			}else{
				echo 'Invalid signature!';
				exit;
			}
	/*		if ($_GET["paytype"] == "advance")		//预存款支付
				$tmp_orderno = $_GET["orderid"];
			else
			{
				$Order->shopId = $INC_SHOPID;
				$Order->payid = $_GET["orderid"];
				$Order->getorderidbyPayid($_GET["orderid"]);		//拿出商店订单号
				$tmp_orderno = $Order->orderId;
			}
			*/

			$reply_result = $Order->getPayresult($_GET["orderid"], $INC_SHOPID);
			$Order->shopId = $INC_SHOPID;
			$Order->orderId = $_GET["orderid"];
			if (!$Order->getbyId($_GET["orderid"]))
			{
				exit('Invalid Order');
			}

			//发送MAIL
			$mailset = newclass("shopMailSetup");
			$mailset->shopid= $INC_SHOPID;
			$mailset->getinfo("pay_success");
			if($mailset->mail_enable == 1)
			{
				$mailset->set_mailvar("shopname",$shopinfo->name);
				$mailset->set_mailvar("orderid",$_GET["orderid"]);
				$mailset->set_mailvar("truename",$Order->name);
				$mailset->set_mailvar("reply_title",$reply_title);
				$mailset->set_mailvar("receiver_address",$Order->address);
				$mailset->set_mailvar("reply_result",$reply_result);

				$mailset->getrealinfo();

				include($INC_SYSHOMEDIR."syssite/smtpmail/sm.php");
				$smtpserver = $shopinfo->smtp_server ;		//SMTP服务器
				$smtpserverport = $shopinfo->smtp_port;		//SMTP服务器端口
				$smtpusermail = $shopinfo->smtp_email ;		//SMTP服务器的用户邮箱(您的邮箱)
				$smtpuser = $shopinfo->smtp_user ;		//SMTP服务器的用户帐号
				$smtppass = $shopinfo->smtp_password ;		//SMTP服务器的用户密码
				$smtp = new smtp($smtpuser,$smtppass,$smtpserver,$smtpserverport,$shopinfo->smtp_ifcheck);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
				//$smtp->debug = true;//是否显示发送的调试信息
				$smtp->encode = $shopinfo->mail_enc;
				$smtp->lang = $FRONTEND_LANG;
				$smtp->sendway = ($shopinfo->smtp_sendmode==1?"MAIL":"SMTP");
				$smtp->sendmail($Order->email, $smtpusermail, $mailset->mail_realtitle , $mailset->mail_realcontent, "TXT", $shopinfo->name);//（$attachment=>附件的编码，$hasfile=>是否含有附件，$file_name=>附件的名称，$content_type=>附件的类型）
			}
			break;
	}

	$t->set_var("payreply_title",$reply_title);		/*支付结果页标题*/
	$t->set_var("payreply_result",$reply_result);		/*支付结果页内容*/
	//$t->set_var("payreply_result",'');		/*支付结果页内容*/
//}
?>